package com.funmi.lizip.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.baomidou.mybatisplus.generator.IFill;
import com.funmi.lizip.common.base.R;
import com.funmi.lizip.entity.*;
import com.funmi.lizip.entity.dto.patrolTrack.PatrolTrackQueryRequest;
import com.funmi.lizip.entity.dto.patrolTrack.TrackMsg;
import com.funmi.lizip.entity.vo.*;
import com.funmi.lizip.mapper.PatrolTrackMapper;
import com.funmi.lizip.service.PatrolService;
import com.funmi.lizip.service.PatrolTrackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.funmi.lizip.service.PersonnelService;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.annotation.PostConstruct;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static com.funmi.lizip.utils.CaculateDistanceTest.getDistanceMeter;
import static java.time.Month.JANUARY;

/**
 * <p>
 *  轨迹
 * </p>
 *
 * @author yeyg
 * @since 2022-11-03
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PatrolTrackServiceImpl extends ServiceImpl<PatrolTrackMapper, PatrolTrack> implements PatrolTrackService {

    @Autowired
    private PatrolTrackMapper patrolTrackMapper;
    @Autowired
    @Lazy
    private PersonnelService personnelService;
    @Autowired
    @Lazy
    private PatrolService patrolService;


    private Double distance = 0.0;
    private Month[] months = new Month[]{JANUARY};
    private Integer year = 0;
    private Integer day = 0;

    @Override
    public Page<AttendanceVo> getDetailed(PatrolTrackQueryRequest request) {
        long current = 1;
        long size = 10;
        // Camera cameraQuery = new Camera();
        current = request.getPage();
        size = request.getPageSize();

        QueryWrapper<Personnel> personnelQueryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(request.getName())) {
            // 遍历所有护林员
            personnelQueryWrapper.like("name", request.getName());
        }
        Page<Personnel> personnelPage = personnelService.page(new Page<>(current, size), personnelQueryWrapper);

        Page<AttendanceVo> attendanceVoPage = new PageDTO(personnelPage.getCurrent(), personnelPage.getSize(), personnelPage.getTotal());
        List<AttendanceVo> statisticsVoList = personnelPage.getRecords().stream().map(personnel -> {
            // 设置护林员
            PersonnelVo personnelVo = new PersonnelVo();
            AttendanceVo attendanceVo = new AttendanceVo();
            BeanUtils.copyProperties(personnel, personnelVo);

            Integer id = personnel.getId();
            QueryWrapper<PatrolTrack> queryWrapper = new QueryWrapper<>();
            queryWrapper.between("patrol_date",
                            (request.getStartPatrolDate() == null)? (LocalDateTime.of(2019, 10, 12, 6, 30)): request.getStartPatrolDate(),
                            (request.getEndPatrolDate() == null)? (LocalDateTime.now()):request.getEndPatrolDate())
                    .eq("ranger_id", id)
                    .eq("status", 0);
            List<PatrolTrack> ranger_id = patrolTrackMapper.selectList(queryWrapper);
            if (ObjectUtils.isEmpty(ranger_id)){
                attendanceVo.setRangerPatrolRegion(personnel.getRangerPatrolRegion());
                attendanceVo.setName(personnel.getName());
                attendanceVo.setId(personnel.getId());
                attendanceVo.setName(personnel.getName());
                attendanceVo.setDistance(distance);
                distance = 0.0;
                attendanceVo.setDay(day);
                day = 0;
                return attendanceVo;
            }
            ranger_id.forEach(patrolTrack -> {
                if (ObjectUtils.isEmpty(patrolTrack)) {
                    return;
                }
                // 通过轨迹查询巡护任务，巡护任务中的任务执行时间。
                day += (int) Duration.between(patrolTrack.getGmtCreate(), patrolTrack.getPatrolDate()).toDays();
                // 如果计算为 0 则至少为一天
                if ((int) Duration.between(patrolTrack.getGmtCreate(), patrolTrack.getPatrolDate()).toDays() <= 0){
                    day += 1;
                }
                distance += patrolTrack.getDistance();

                // attendanceVo.setMonth(months);
                attendanceVo.setRangerPatrolRegion(personnel.getRangerPatrolRegion());
                attendanceVo.setName(personnel.getName());
                attendanceVo.setId(personnel.getId());
                //attendanceVo.setYear(year);
                //year = 0;
            });
            attendanceVo.setName(personnel.getName());
            attendanceVo.setDistance(distance);
            distance = 0.0;
            attendanceVo.setDay(day);
            day = 0;
            return attendanceVo;
        }).collect(Collectors.toList());
        // statisticsVoList.removeAll(Collections.singleton(null));
        // 根据天数排序
        List<AttendanceVo> collect = statisticsVoList.stream().sorted(Comparator.comparing(AttendanceVo::getDistance)).collect(Collectors.toList());
        attendanceVoPage.setRecords(collect);

        return attendanceVoPage;
    }

    /**
     * 通过id返回
     * @param id
     * @return PatrolTrack
     */
    @Override
    public PatrolTrack getByRangerId(Integer id) {
        QueryWrapper<PatrolTrack> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ranger_id", id);
        return patrolTrackMapper.selectOne(queryWrapper);
    }


    /**
     * 通过巡护员id 获取轨迹通勤详情
     * @param id
     * @return List<PatrolTrackVo>
     */
    @Override
    public List<PatrolTrackByIdVo> getStatistics(int id) {
        /*Personnel one = personnelService.getOne(new QueryWrapper<>(new Personnel(rangerId)));
        String rangerName = one.getName();
        Personnel personnel = new Personnel();*/
        QueryWrapper<PatrolTrack> patrolTrackQueryWrapper = new QueryWrapper<>();
        patrolTrackQueryWrapper.eq("ranger_id", id)
                                .eq("status", 0);
        List<PatrolTrack> patrolTracks = patrolTrackMapper.selectList(patrolTrackQueryWrapper);
        List<PatrolTrackByIdVo> patrolTrackByIdVos = new ArrayList<>();
        patrolTracks.forEach(patrolTrack -> {
            PatrolTrackByIdVo patrolTrackByIdVo = new PatrolTrackByIdVo();
            BeanUtils.copyProperties(patrolTrack, patrolTrackByIdVo);
            if (!ObjectUtils.isEmpty(patrolTrack) && !ObjectUtils.isEmpty(patrolTrack.getPatrolDate())){
                //patrolTrackByIdVo.setDay((int) Duration.between(patrolTrack.getGmtCreate(), patrolTrack.getPatrolDate()).toDays());
            }
            patrolTrackByIdVo.setName(personnelService.getNameById(Integer.valueOf(patrolTrack.getRangerId())));
            patrolTrackByIdVos.add(patrolTrackByIdVo);
        });
        return patrolTrackByIdVos;



        /*long current = 1;
        long size = 10;
        Camera cameraQuery = new Camera();
        if (request != null){
            current = request.getPage();
            size = request.getPageSize();
        }
        // 通过名字获取id
        patrolTrackQueryWrapper.eq("ranger_id", rangerId);

        patrolTrackQueryWrapper
                .between("gmt_create",
                (request.getStartPatrolDate() == null)? (LocalDateTime.of(2019, 10, 12, 6, 30)): request.getStartPatrolDate(),
                (request.getEndPatrolDate() == null)? (LocalDateTime.now()):request.getEndPatrolDate())
                .eq("status", "0");
        // List<PatrolTrack> patrolTracks = patrolTrackMapper.selectList(patrolTrackQueryWrapper);
        Page<PatrolTrack> patrolTrackPage = patrolTrackMapper.selectPage(new Page<>(current, size), patrolTrackQueryWrapper);

        Page<PatrolTrackVo> patrolTrackVoPage = new PageDTO(patrolTrackPage.getCurrent(), patrolTrackPage.getSize(), patrolTrackPage.getTotal());
        List<PatrolTrackVo> patrolTrackVoList = patrolTrackPage.getRecords().stream().map(patrolTrack -> {
            PatrolTrackVo patrolTrackVo = new PatrolTrackVo();
            BeanUtils.copyProperties(patrolTrack, patrolTrackVo);
            return patrolTrackVo;
        }).collect(Collectors.toList());
        patrolTrackVoPage.setRecords(patrolTrackVoList);
            // 参数修改
        Month month = LocalDateTime.now().getMonth();
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        int i = now.compareTo(LocalDateTime.now());
        System.out.println(i);
        return patrolTrackVoPage;*/



    }

    /**
     * 轨迹添加
     * @param request
     * @return boolean
     */
    @Override
    public boolean savePatrolTrack(HashMap<String, Object> request) {

        // PatrolTrack patrolTrack = JSONObject.parseObject(JSONObject.toJSONBytes(request), PatrolTrack.class);
        QueryWrapper<PatrolTrack> patrolTrackQueryWrapper = new QueryWrapper<>();
        patrolTrackQueryWrapper.eq("status", true);
        if(!ObjectUtils.isEmpty(request.get("equipment_number"))) {
            patrolTrackQueryWrapper.eq("equipment_number", request.get("equipment_number"));
        }
        List<PatrolTrack> patrolTracks = patrolTrackMapper.selectList(patrolTrackQueryWrapper);
        // 判断 新增、追加
        if (ObjectUtils.isEmpty(patrolTracks) && ObjectUtils.isEmpty(patrolTracks.get(0))){
            R.fail().message("没有正在进行的轨迹");
            return false;
        }
        // 有数据，追加json并且计算距离 //11.23 不计算距离, 仅累加轨迹
        PatrolTrack patrolTrack = patrolTracks.get(0);
        //计算距离
        JSONArray trackMsg = patrolTrack.getTrackMsg();
        String s = trackMsg.toJSONString();
        List<JSONObject> arrayLists = JSON.parseArray(s, JSONObject.class);
        //JSONObject jsonObject = arrayLists.get(arrayLists.size() - 1);
        //Map<String, Object> innerMap = jsonObject.getInnerMap();
        //Object location = innerMap.get("location");
        //List<Double> arrayLists1 = JSONArray.parseArray(location.toString(), Double.class);

        Object track_msg = request.get("track_msg");
        //List<JSONObject> arrayLists2 = JSON.parseArray(track_msg.toString(), JSONObject.class);
        //JSONObject jsonObject2 = arrayLists.get(arrayLists2.size() - 1);
        //Map<String, Object> innerMap2 = jsonObject2.getInnerMap();
        //Object location2 = innerMap2.get("location");
        //List<Double> arrayLists3 = JSONArray.parseArray(location2.toString(), Double.class);

        //GlobalCoordinates source = new GlobalCoordinates(arrayLists1.get(0), arrayLists1.get(1));
        //GlobalCoordinates target = new GlobalCoordinates(arrayLists3.get(0), arrayLists3.get(1));
        //double meter = getDistanceMeter(source, target, Ellipsoid.Sphere);
        // 添加距离
        // patrolTrack.setDistance(meter);
        // 追加轨迹
        StringBuilder stringBuffer = new StringBuilder();
        StringBuilder append = stringBuffer.append(s).append(track_msg);
        StringBuilder replace = append.replace(s.length()-1, s.length() + 1, ", ");
        JSONArray objects = JSONArray.parseArray(String.valueOf(replace));
        patrolTrack.setTrackMsg(objects);

        int i = patrolTrackMapper.updateById(patrolTrack);
        return i == 1;
    }


    /**
     * 添加时候 计算距离
     * @param request
     * @return
     */

    public boolean saveDistance(HashMap<String, Object> request) {
        Object track_msg = request.get("track_msg");
        return false;
    }


    /**
     * 图表总体统计出勤
     * @return StatisticsAllVo
     */
    @Override
    public StatisticsAllVo getStatisticsAll() {
        StatisticsAllVo statisticsAllVo = new StatisticsAllVo();
        List<Personnel> attendance;
        List<Personnel> noAttendance = null;
        // 本月 出勤人数 和 未出勤人数
        QueryWrapper<PatrolTrack> patrolTrackQueryWrapper = new QueryWrapper<>();
        patrolTrackQueryWrapper.between("patrol_date", LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth())
                        ,LocalDateTime.now().with(TemporalAdjusters.lastDayOfMonth()))
                .eq("status", false);
        List<PatrolTrack> patrolTracks = patrolTrackMapper.selectList(patrolTrackQueryWrapper);
        List<Personnel> list = personnelService.list();
        // 去重的护林员id集合
        Set<Integer> collect = patrolTracks.stream().map(patrolTrack -> Integer.valueOf(patrolTrack.getRangerId())).collect(Collectors.toSet());
        /*QueryWrapper<Personnel> queryWrapper = new QueryWrapper<>();

        queryWrapper.in("id", collect.toString());
        attendance = personnelService.list(queryWrapper);*/
        // statisticsAllVo.setAttendance(attendance.size());
        statisticsAllVo.setAttendance(collect.size());
        // patrolTrackMapper
        /*noAttendance = list.stream()
                .filter(notComment -> !attendance.stream().map(Personnel::getId).collect(Collectors.toList()).contains(notComment.getUserId()))
                .collect(Collectors.toList());*/
        statisticsAllVo.setNoAttendance((int)personnelService.count() - collect.size());
        // private Map<String, Integer> person; ranger_patrol_region 护林员巡护区域 ranger_duty_area_code 护林员责任区号
        HashMap<String, Integer> person = new HashMap<>();
        Set<String> regions = list.stream().map(Personnel::getRangerPatrolRegion).collect(Collectors.toSet());
        regions.forEach(region -> {
            QueryWrapper<Personnel> personnelQueryWrapper = new QueryWrapper<>();
            personnelQueryWrapper.eq("ranger_patrol_region", region);
            long count = personnelService.count(personnelQueryWrapper);
            person.put(region, (int) count);
        });

        statisticsAllVo.setPerson(person);

        // 月单位出勤率排名 // 月出勤率统计
        // 获取所有任务
        /*QueryWrapper<Patrol> patrolQueryWrapper = new QueryWrapper<>();
        patrolQueryWrapper.between("start_time", LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth())
                        ,LocalDateTime.now().with(TemporalAdjusters.lastDayOfMonth()))
                .eq("status", 2);*/

        HashMap<String, Integer> regionCode = new HashMap<>();
        // 获取巡护任务区域名称
        List<Patrol> patrolList = patrolService.list();
        Set<String> patrolRegion = patrolList.stream().map(Patrol::getRegion).collect(Collectors.toSet());
        patrolRegion.forEach(region ->{
            QueryWrapper<Patrol> wrapper = new QueryWrapper<>();
            wrapper.eq("region", region)
                    .between("start_time", LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth())
                            ,LocalDateTime.now().with(TemporalAdjusters.lastDayOfMonth()))
                    .eq("status", 2);
            regionCode.put(region, (int)patrolService.count(wrapper));
        });
        List<HashMap.Entry<String,Integer>> list2 = new ArrayList<>(regionCode.entrySet());
        //降序排序
        list2.sort((o1, o2) -> o2.getValue().compareTo(o1.getValue()));
        LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
        for (Map.Entry<String, Integer> stringIntegerEntry : list2) {
            map.put(stringIntegerEntry.getKey(), stringIntegerEntry.getValue());
        }

        /*for(Map.Entry<String,String> mapping:list){
            System.out.println(mapping.getKey()+":"+mapping.getValue());
        }*/
        statisticsAllVo.setMonthlyRanking(map);


        // 年单位出勤率排名 // 年出勤率统计
        // 获取所有任务
        // 获取巡护任务区域名称
        LinkedHashMap<String, Integer> yearMap = new LinkedHashMap<>();
        patrolRegion.forEach(region ->{
            QueryWrapper<Patrol> wrapper = new QueryWrapper<>();
            wrapper.eq("region", region)
                    .between("start_time", LocalDateTime.now().with(TemporalAdjusters.firstDayOfYear())
                            ,LocalDateTime.now().with(TemporalAdjusters.lastDayOfYear()))
                    .eq("status", 2);
            regionCode.put(region, (int)patrolService.count(wrapper));
        });
        List<HashMap.Entry<String,Integer>> list3 = new ArrayList<>(regionCode.entrySet());
        //降序排序
        list3.sort((o1, o2) -> o2.getValue().compareTo(o1.getValue()));
        for (Map.Entry<String, Integer> stringIntegerEntry : list2) {
            yearMap.put(stringIntegerEntry.getKey(), stringIntegerEntry.getValue());
        }

        /*for(Map.Entry<String,String> mapping:list){
            System.out.println(mapping.getKey()+":"+mapping.getValue());
        }*/
        statisticsAllVo.setYearRanking(yearMap);

        // 月单位出勤率排名 // 月出勤率统计
        // 获取所有任务
        /*QueryWrapper<Patrol> patrolQueryWrapper2 = new QueryWrapper<>();
        patrolQueryWrapper2.between("patrol_date",LocalDateTime.of(LocalDate.from(LocalDateTime.now().with(TemporalAdjusters.firstDayOfYear())), LocalTime.MIN)
                        ,LocalDateTime.of(LocalDate.from(LocalDateTime.now().with(TemporalAdjusters.lastDayOfYear())), LocalTime.MAX))
                .eq("status", 0);
        // 任务根据责任区号分类
        regions.forEach(s -> {
            String dutyAreaCode = personnelService.list(new QueryWrapper<Personnel>().eq("ranger_patrol_region", s)).get(0).getRangerDutyAreaCode();
            // 责任区号替换为区域名称
            long duty_area_code = patrolService.count(new QueryWrapper<Patrol>().eq("duty_area_code", dutyAreaCode));
            regionCode.put(s, (int)duty_area_code);
        });*/

        return statisticsAllVo;

        }


    /**
     * 护林员上传轨迹
      * @param patrolTrack
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean insertPatrolTrack(PatrolTrack patrolTrack) {
        GlobalCoordinates source;
        GlobalCoordinates target;
        if (ObjectUtils.isEmpty(patrolTrack)){
            return false;
        }
        if (!ObjectUtils.isEmpty(patrolTrack.getTrackMsg())){
            JSONArray trackMsg = patrolTrack.getTrackMsg();
            String s = trackMsg.toString();
            List<TrackMsg> trackMsgs = JSONArray.parseArray(s, TrackMsg.class);
            List<TrackMsg> collect = trackMsgs.stream().sorted(Comparator.comparing(TrackMsg::getCreateTime)).collect(Collectors.toList());
            for (int i = 0; i < collect.size() - 1; i++) {
                List<Double> doubles = JSONArray.parseArray(collect.get(0).getLocation().toString(), Double.class);
                source = new GlobalCoordinates(doubles.get(0), doubles.get(1));
                List<Double> doubles2 = JSONArray.parseArray(collect.get(1).getLocation().toString(), Double.class);
                target = new GlobalCoordinates(doubles2.get(0), doubles.get(1));

                double meter1 = getDistanceMeter(source, target, Ellipsoid.Sphere);
                distance += meter1;
            }
            distance = (double) (distance.floatValue() / 1000);
            patrolTrack.setDistance(distance);
        }
        // 同时结束巡护任务, 将任务状态置为 2
        QueryWrapper<Patrol> patrolQueryWrapper = new QueryWrapper<>();
        patrolQueryWrapper.eq("status", 1);
        patrolQueryWrapper.eq("id", patrolTrack.getPatrolId());
        Patrol one = patrolService.getOne(patrolQueryWrapper);
        if (ObjectUtils.isEmpty(one)){
            return false;
        }
        one.setStatus(2);
        // 巡护任务结束时间
        one.setEndTime(LocalDateTime.now());
        boolean b = patrolService.updateById(one);
        if (!b){
            return false;
        }

        int insert = patrolTrackMapper.updateById(patrolTrack);

        return insert == 1;
    }

    /**
     * 通过人员定位，累加经纬度轨迹
     * @param latitude
     * @param longitude
     * @return boolean
     */
    @Override
    public boolean savePatrolTrack(String latitude, String longitude) {
        // 从登录态中获取
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        String name = authentication.getName();
        QueryWrapper<Personnel> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("contact_tel", name);
        Personnel one = personnelService.getOne(userQueryWrapper);

        if (ObjectUtils.isEmpty(one)){
            R.fail().message("用户错误");
            return false;
        }
        QueryWrapper<PatrolTrack> patrolTrackQueryWrapper = new QueryWrapper<>();
        patrolTrackQueryWrapper.ne("status", false);
        patrolTrackQueryWrapper.eq("ranger_id", one.getId());
        List<PatrolTrack> patrolTracks = patrolTrackMapper.selectList(patrolTrackQueryWrapper);
        // 判断 新增、追加
        if (patrolTracks.size() <= 0 || ObjectUtils.isEmpty(patrolTracks.get(0))){
            R.fail().message("没有正在进行的轨迹");
            return false;
        }
        // 不计算距离, 仅累加轨迹
        PatrolTrack patrolTrack = patrolTracks.get(0);
        JSONArray trackMsg = patrolTrack.getTrackMsg();
        String s="";
        if(!ObjectUtils.isEmpty(trackMsg)){
            s = trackMsg.toJSONString();
            String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            // List<JSONObject> arrayLists = JSON.parseArray(s, JSONObject.class);
            // 通过经纬度获取, 拼凑方式: 纬度在前 经度在后
            String track_msg = "{\"location\": ["+ longitude +", " + latitude + "], \"createTime\": \""+ format +"\"}";

            StringBuilder stringBuffer = new StringBuilder();
            StringBuilder append = stringBuffer.append(s).append(track_msg).append("]");;
            StringBuilder replace = append.replace(s.length()-1, s.length(), ", ");
            JSONArray objects = JSONArray.parseArray(String.valueOf(replace));
            patrolTrack.setTrackMsg(objects);

            int i = patrolTrackMapper.updateById(patrolTrack);
            return i == 1;
        }

        String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        // List<JSONObject> arrayLists = JSON.parseArray(s, JSONObject.class);
        // 通过经纬度获取, 拼凑方式: 纬度在前 经度在后
        String track_msg = "[{\"location\": ["+ latitude +", " + longitude + "], \"createTime\": \""+ format +"\"}]";
        JSONArray objects = JSONArray.parseArray(track_msg);
        patrolTrack.setTrackMsg(objects);

        int i = patrolTrackMapper.updateById(patrolTrack);
        return i == 1;
    }


    /**
     * 新建一个巡护轨迹
     * @param request
     * @return
     */
    private boolean insert(HashMap<String, Object> request) {
        Object name = request.get("name");
        QueryWrapper<Personnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name.toString());
        Personnel one = personnelService.getOne(queryWrapper);
        // 获取护林员Id
        Integer id = one.getId();
        if (id == 0){
            return false;
        }
        PatrolTrack patrolTrack = new PatrolTrack();
        //patrolTrack.se(LocalDateTime.now());
        patrolTrack.setDelete(false);
        patrolTrack.setEquipmentNumber(request.get("equipment_number").toString());
        patrolTrack.setPatrolId(request.get("patrol_id").toString());
        patrolTrack.setRangerId(id.toString());
        patrolTrack.setStatus(true);
        patrolTrack.setDistance((double)0);
        return true;
    }



}
